using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Storage;
using System;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class MassSendListItem : StackPanel, MMItemCtrl
	{
		private const string TAG = "MassSendListItem";
		private FrameworkElement realElement;
		public static DependencyProperty ListItemProperty;
		public MassMsg ItemObject
		{
			get
			{
				return (MassMsg)base.GetValue(MassSendListItem.ListItemProperty);
			}
			set
			{
				base.SetValue(MassSendListItem.ListItemProperty, value);
			}
		}
		public MassSendListItem()
		{
			base.add_Loaded(new RoutedEventHandler(this.MassSendItem_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.MassSendItem_Unloaded));
		}
		private void MassSendItem_Loaded(object sender, RoutedEventArgs e)
		{
			this.Refresh();
		}
		private void MassSendItem_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		public void Refresh()
		{
			MassMsg itemObject = this.ItemObject;
			if (itemObject == null)
			{
				return;
			}
			if (this.realElement == null)
			{
				return;
			}
			BaseMassSendElement baseMassSendElement = this.realElement as BaseMassSendElement;
			baseMassSendElement.SetMassMsg(itemObject);
			if (itemObject.IsTime())
			{
				return;
			}
			if (itemObject.IsTxt())
			{
				baseMassSendElement.SetMsgContent(itemObject.strContent);
				return;
			}
			if (itemObject.IsImage())
			{
				baseMassSendElement.SetImgSrc(itemObject.strThumbFileName);
				return;
			}
			if (itemObject.IsVoice())
			{
				baseMassSendElement.SetVoiceLen((itemObject.nMediaTime + 499) / 1000);
			}
		}
		private FrameworkElement getItemByMsg(MassMsg item)
		{
			if (item.IsTime())
			{
				return new MassSendTimeItem();
			}
			if (item.IsTxt())
			{
				return new MassSendTxtItem();
			}
			if (item.IsImage())
			{
				return new MassSendImgItem();
			}
			if (item.IsVoice())
			{
				return new MassSendVoiceItem();
			}
			return this.realElement;
		}
		static MassSendListItem()
		{
			MassSendListItem.ListItemProperty = DependencyProperty.Register("ItemObject", typeof(MassMsg), typeof(MassSendListItem), new PropertyMetadata(null, new PropertyChangedCallback(MassSendListItem.OnItemPropertyChanged)));
		}
		private static void OnItemPropertyChanged(DependencyObject dependencyObject_0, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			if (dependencyPropertyChangedEventArgs_0.get_Property() == MassSendListItem.ListItemProperty)
			{
				(dependencyObject_0 as MassSendListItem).OnListItemPropertyChanged(dependencyPropertyChangedEventArgs_0);
			}
		}
		private void OnListItemPropertyChanged(DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs_0)
		{
			try
			{
				this.RefreshItem(dependencyPropertyChangedEventArgs_0.get_NewValue() as MassMsg);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), ex.get_StackTrace());
			}
		}
		private void RefreshItem(MassMsg item)
		{
			if (item == null)
			{
				return;
			}
			if (this.realElement == null)
			{
				this.realElement = this.getItemByMsg(item);
				base.get_Children().Add(this.realElement);
			}
			this.Refresh();
		}
	}
}
